import { CommentService } from './comment.service';
import { Body, Controller, Get, HttpCode, HttpException, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
import { TokenAuth } from 'src/common/gaurd/tokenAuth.gaurd';
import { commentDto } from '../dto/comment.dto';
import { ApiHeader, ApiProperty, ApiTags } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

@Controller('comment')
@UseGuards(TokenAuth)
@ApiTags('information/comment')
export class CommentController {
  constructor(private CommentService :CommentService){}
  @Post('/public')
  async publicComment(@Body() data :commentDto,@Req() req:any) {
          // console.log(data)
          let user_id = req.user_info.id
        let result = await this.CommentService.public(data,user_id)
        if(result.id>0){
             return {
              code:1,
              message:'评论成功'
             }
        }
  }

  
  /**
  * @author nie  
  * @description 获取文章下的评论
  * @email a896211755@gmail.com
  */
  @Get('/getCommentWithInfoId')
  @HttpCode(200)
  // @ApiProperty({})
  async getCommentList(@Query("id") id :number){
    if(!id){
      throw new HttpException("参数错误",400)
    }
     return this.CommentService.commentListWithInfoIdOrUserId(id,1)
  }
   /**
  * @author nie  
  * @description 获取用户的所有评论
  * @email a896211755@gmail.com
  */
   @Get('/getCommentWithUserId')
   @HttpCode(200)
   // @ApiProperty({})
   @ApiHeader({
         name:'authorization',
         description:"用户token",
         required:true,
   })
   async getCommentListWithUserId(@Query("id") id :number){
     if(!id){
       throw new HttpException("参数错误",400)
     }
      return this.CommentService.commentListWithInfoIdOrUserId(id,1)
   }


} 
